<template>
  <el-card>
    <el-input
      v-model="page.input"
      placeholder="请输入内容进行查询"
      :clearable="true"
      style="width: 30%; float: left; margin-bottom: 10px"
    ></el-input>

    <el-button
      type="primary"
      @click="loadWarning()"
      style="width: 5%; float: left; margin-left: 10px"
      ><i class="el-icon-search"></i
    ></el-button>
    <el-table :data="tableData" border style="width: 100%">
      <el-table-column prop="borwarningGrade" label="预警等级" width="180">
      </el-table-column>
      <el-table-column prop="borwarningBy2" label="借贷人"> </el-table-column>
      <el-table-column prop="productId" label="借贷金额"> </el-table-column>
      <el-table-column prop="borwarningBy1" label="借贷类型"> </el-table-column>

      <el-table-column prop="borwarningDays" label="预警周期" width="180">
      </el-table-column>

      <el-table-column label="操作" align="center">
        <template slot-scope="scope">
          <el-button @click="handleClick(scope.row)" type="text" size="big"
            >详情查看</el-button
          >
          <el-button
            type="primary"
            @click="
              handleCheck(scope.row.borwarningId, scope.row.borwarningGrade)
            "
            >检查</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="page.currentPage"
      :page-sizes="pageInfo.pageSizes"
      :page-size="page.pagesize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="pageInfo.total"
    >
    </el-pagination>
    <!-- ------------------------检查模态框---------------------------- -->
    <el-dialog title="修改" :visible.sync="dialog.checkShow" width="40%">
      <el-form ref="form" :model="checkForm" label-width="100px" size="medium">
        <el-form-item label="检查人员配送" prop="staffId">
          <el-select
            v-model="checkForm.checkUsername"
            placeholder="请选择"
            style="width: 100%"
          >
            <el-option
              v-for="item in empList"
              :key="item.empId"
              :label="item.empName"
              :value="item.empName"
            >
            </el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialog.checkShow = false">取 消</el-button>
        <el-button type="primary" @click="insertCheck()">确 定</el-button>
      </span>
    </el-dialog>
  </el-card>
</template>

<script>
export default {
  data() {
    return {
      page: {
        currentPage: 1,
        pagesize: 5,
        input: "",
      },
      pageInfo: {
        total: 0,
        pageSizes: [5, 20, 30, 50, 100],
      },
      tableData: "",
      dialog: {
        checkShow: false,
      },
      checkForm: {},
      empList: {},
    };
  },
  methods: {
    insertCheck() {
      this.dialog.checkShow = false;
      this.$axios.post("/Checked", this.checkForm).then((res) => {
        if (res.data.code == 200) {
          this.$message.success("检查人员推送成功");
        }
      });
    },
    handleCheck(id, grade) {
      this.dialog.checkShow = true;
      this.checkForm.borwarningId = id;
      this.checkForm.borwarningGrade = grade;
      this.$axios.post("/emps/selAll").then((res) => {
        this.empList = res.data.data.empList;
      });
    },
    loadWarning() {
      this.$axios.post("/BorWarning/page", this.page).then((res) => {
        this.tableData = res.data.data.list;
        this.pageInfo.total = res.data.data.pageInfo;
      });
    },
    //当每页显示条数改变时
    handleSizeChange(size) {
      this.page.pagesize = size;
      this.loadWarning();
    },
    //当页数改变时
    handleCurrentChange(currentPage) {
      this.page.currentPage = currentPage;
      this.loadWarning();
    },
  },
  mounted() {
    this.loadWarning();
  },
};
</script>